package ;

/**
 * ...
 * @author test
 */
//TODO: Must use Dynamic objects.
class EnemyPool {
	//Array containing the enemies.
	var enemies:Array<Enemy>;

	//Current index.
	var current:Int;

	//Constructor... nothing else to say here.
	public function new(size:Int) {
		this.enemies = new Array<Enemy>();
		this.current = 0;
		for (i in 0...size) {
			this.enemies.push(new Enemy());
		}
	}

	//Getters and setters - BEGIN
	private function getEnemies():Array<Enemy> {
		return this.enemies;
	}

	private function getCurrent():Int {
		return this.current;
	}

	private function setCurrent(current:Int):Void {
		this.current = current;
	}
	//Getters and setters - END

	//Method to obtain an available enemy. If no enemy is available, returns null.
	public function getAvailableEnemy():Enemy {
		var index:Int = this.getCurrent();
		var enemy:Enemy = null;

		do {
			if (this.getEnemies()[index].visible == false) {
				enemy = this.getEnemies()[index];
			}
			index++;
			if (index == this.getEnemies().length) {
				index = 0;
			}			
		} while ( (index != this.getCurrent()) && (enemy == null) );

		this.setCurrent(index);

		return enemy;
	}
}